# 海康威视相机物体识别系统启动器 (PowerShell版本)
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "    海康威视相机物体识别系统启动器" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""

# 检查Python环境
Write-Host "正在检查Python环境..." -ForegroundColor Yellow
try {
    $pythonVersion = python --version 2>&1
    Write-Host "Python环境检查通过: $pythonVersion" -ForegroundColor Green
} catch {
    Write-Host "错误: 未找到Python环境，请先安装Python 3.7+" -ForegroundColor Red
    Read-Host "按任意键退出"
    exit 1
}

Write-Host ""

# 安装依赖包
Write-Host "正在检查并安装必要的依赖包..." -ForegroundColor Yellow

$packages = @(
    "PyQt5",
    "opencv-python", 
    "numpy",
    "ultralytics",
    "paddleocr"
)

foreach ($package in $packages) {
    Write-Host "安装 $package..." -ForegroundColor Yellow
    pip install $package -i https://pypi.tuna.tsinghua.edu.cn/simple/ --quiet
    if ($LASTEXITCODE -eq 0) {
        Write-Host "$package 安装成功" -ForegroundColor Green
    } else {
        Write-Host "$package 安装失败" -ForegroundColor Red
    }
}

Write-Host ""
Write-Host "依赖安装完成！" -ForegroundColor Green
Write-Host ""

# 启动程序
Write-Host "正在启动物体识别系统..." -ForegroundColor Yellow
Write-Host "请确保相机已连接并正常工作" -ForegroundColor Yellow
Write-Host ""

# 切换到BasicDemo目录并运行程序
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$basicDemoPath = Join-Path $scriptDir "BasicDemo"
Set-Location $basicDemoPath

python object_recognition_demo.py

Write-Host ""
Write-Host "程序已退出" -ForegroundColor Yellow
Read-Host "按任意键退出" 